<template>
  <HomePanel title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
    <ul class="goods-list">
      <li v-for="item in newList" :key="item.id">
        <RouterLink :to="`/detail/${item.id}`">
          <el-image :src="item.picture" lazy></el-image>
          <p class="name">{{ item.name }}</p>
          <p class="price">{{ item.price }}</p>
        </RouterLink>
      </li>
    </ul>
  </HomePanel>
</template>

<script setup>
import HomePanel from './HomePanel.vue'
import { ref } from 'vue'
import { findNewApi } from '@/apis/home'

const newList = ref([])
const getNewList = async () => {
  const { result } = await findNewApi()
  newList.value = result
}
getNewList()
</script>

<style lang="scss" scoped>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;

  li {
    width: 306px;
    height: 406px;
    transition: all 0.5s;
    a {
      display: block;
      height: 100%;
    }

    &:hover {
      transform: translate3d(0, -3px, 0);
      box-shadow: 0 3px 8px rgb(0 0 0 / 20%);
    }

    p {
      line-height: 50px;
      font-size: 22px;
      text-align: center;

      /* 1. 强制文本在一行内显示 */
      white-space: nowrap;
      /* 2. 隐藏超出容器的内容 */
      overflow: hidden;
      /* 3. 用省略号代替超出的部分 */
      text-overflow: ellipsis;
      &.name {
        font-size: 22px;
        padding: 0 8px;
      }
      &.price {
        font-size: 24px;
        color: red;
      }
    }
  }
}
</style>
